package com.lm.controller;

import com.lm.service.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * redis分布式测试
 *
 * @author LM
 * @date 2025/2/7 13:53
 */
@RestController
@Api(tags = "redis分布式测试")
public class InventoryController {

    @Resource
    private InventoryService inventoryService;

    @ApiOperation("扣减库存")
    @GetMapping("/inventory/sale")
    public String sale() {
        return inventoryService.sale4();
    }

    @ApiOperation("扣减库存使用Redisson")
    @GetMapping(value = "/inventory/saleByRedisson")
    public String saleByRedisson() {
        return inventoryService.saleByRedisson();
    }

    @ApiOperation("扣减库存使用自定义注解")
    @GetMapping(value = "/inventory/saleByRedisLock")
    public String saleByRedisLock(@RequestParam("id") Long id) {
        return inventoryService.saleByRedisLock(id);
    }
}
